﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MDM
{
    public class SqlHelper
    {
        private readonly static string sqlconnectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
        public static SqlConnection GetConnection()
        {
            var connection = new SqlConnection(sqlconnectionString);
            connection.Open();
            return connection;
        }


        /// <summary>
        /// 执行SQL语句,返回 DataTable
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="conn"></param>
        /// <returns></returns>
        #region 执行SQL语句。返回 DataTable +DataTable ExecuteDataTable(string sql)
        public static DataTable ExecuteDataTable(string sql, SqlConnection conn)
        {
            SqlCommand sqlCommand = new SqlCommand(sql, conn);
            DataTable retrunDataTable = new DataTable();
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand);

            sqlDataAdapter.Fill(retrunDataTable);
            return retrunDataTable;


        }
        #endregion

    }
}
